import NoFound from "@/components/NoFound/index.vue"
import Blog from '@/views/Blog/index.vue'
import BlogDetailVue from "@/views/Blog/Detail/index.vue";
import 'nprogress/nprogress.css';
import {start, done, configure} from "nprogress";
import { defineAsyncComponent} from 'vue';

configure({
    trickleSpeed: 20,
    showSpinner: false
})

function delay(duration:number){
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(null);
        }, duration);
    })
}

function getPageComponent(pageCompResolve:any){
    return async () => {
        start();
        if(process.env.NODE_ENV === 'development'){
            await delay(2000);
        }
        const result = defineAsyncComponent(pageCompResolve)
        done();
        return result;
    }
}
const routes = [
    {
        name: 'Home',
        path: '/',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "home"*/ '@/views/Home/index.vue')
        ),
        meta: { title: '首页' },
      },
      {
        name: 'Message',
        path: '/message',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "message"*/ '@/views/Message/index.vue')
        ),
        meta: { title: '留言板' },
      },
      {
        name: 'About',
        path: '/about',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "about"*/ '@/views/About/index.vue')
        ),
        meta: { title: '关于我' },
      },
      {
        name: 'Blog',
        path: '/blog',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "blog"*/ '@/views/Blog/index.vue')
        ),
        meta: { title: '文章' },
      },
      {
        name: 'BlogCategory',
        path: '/blog/cate/:categoryId',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "blogcategory"*/ '@/views/Blog/index.vue')
        ),
        meta: { title: '文章分类' },
      },
      {
        name: 'BlogDetail',
        path: '/blog/:id',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "blogdetail"*/ '@/views/Blog/Detail/index.vue')
        ),
        meta: { title: '文章详情' },
      },
      {
        name: 'Project',
        path: '/project',
        component: getPageComponent(() =>
          import(/*webpackChunkName: "project"*/ '@/views/Project/index.vue')
        ),
        meta: { title: '项目&效果' },
      },
    { name: 'NoFound', path: '/:pathMatch(.*)*', component: NoFound, meta: {title: '没有找到页面'}}
];

export default routes;
